//
//  XLUnlockSettingAdapter.m
//  industry
//
//  Created by xl on 2020/12/14.
//  Copyright © 2020 Haier. All rights reserved.
//

#import "XLUnlockSettingAdapter.h"
#import "XLUnlockSettingCell.h"


NSString *const XLUnlockSettingAdapterPasswordUnlock = @"XLUnlockSettingAdapterPasswordUnlock";
NSString *const XLUnlockSettingAdapterGestureUnlock = @"XLUnlockSettingAdapterGestureUnlock";
NSString *const XLUnlockSettingAdapterFingerprintUnlock = @"XLUnlockSettingAdapterFingerprintUnlock";
NSString *const XLUnlockSettingAdapterBrushFaceUnlock = @"XLUnlockSettingAdapterBrushFaceUnlock";
NSString *const XLUnlockSettingAdapterNoneUnlock = @"XLUnlockSettingAdapterNoneUnlock";

@implementation XLUnlockSettingAdapter

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.getAdapterArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 64.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return [UITableViewCell new];
    }
    id data = self.getAdapterArray[indexPath.row];
    static NSString *cellIdentifierId = @"XLUnlockSettingCell";
    XLUnlockSettingCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifierId];
    if (!cell) {
        cell = [[XLUnlockSettingCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifierId];
    }
    BOOL isHidden = ![data isEqualToString:self.type];
    if ([data isEqualToString:XLUnlockSettingAdapterPasswordUnlock]) {
        [cell loadCellData:@"密码解锁" isHidden:isHidden];
    } else if ([data isEqualToString:XLUnlockSettingAdapterGestureUnlock]) {
        [cell loadCellData:@"手势解锁" isHidden:isHidden];
    } else if ([data isEqualToString:XLUnlockSettingAdapterFingerprintUnlock]) {
        [cell loadCellData:@"指纹解锁" isHidden:isHidden];
    } else if ([data isEqualToString:XLUnlockSettingAdapterBrushFaceUnlock]) {
        [cell loadCellData:@"刷脸解锁" isHidden:isHidden];
    } else if ([data isEqualToString:XLUnlockSettingAdapterNoneUnlock]) {
        [cell loadCellData:@"无" isHidden:isHidden];
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row > self.getAdapterArray.count - 1) {
        return;
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    id cellData = self.getAdapterArray[indexPath.row];
    
    if (self.adapterDelegate && [self.adapterDelegate respondsToSelector:@selector(didSelectCellData:)]) {
        [self.adapterDelegate didSelectCellData:cellData];
    }
}

@end
